package demo.api.trustsign;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import util.HttpClientUtil;

/**
 * 对消息（电子报文）进行数字签名
 *
 */
public class MessageSignature {
	private static String appKey = "cAwut4VATycNMq17NZeFUD63pe83l2OJ";
    private static String appSecrty = "3BAlrfr7lW8kwlCMfo1dXS8Syn5q5qjS";
    private static String baseUrl = "http://smp-test.szitrus.com.cn/smp-api";
    private static String api = "/api/trustsign/message/signature";
    
	public static void main(String[] args) throws IOException {
		String url = baseUrl.concat(api);
		Map<String, String> params = new HashMap<>();

		params.put("user_id", "2");
	    params.put("plaintext", "我是签名原文");
	    params.put("data_type","text");//base64, hex, text;
	    params.put("format","detach");//raw=PKCS#1,attach=PKCS#7 attached, detach=PKCS#7 Detached
	    params.put("algorithm","SHA256withRSA");
	    
	        
	    String resStr =  HttpClientUtil.getResponse(url, params, appKey, appSecrty);
	    JSONObject resJson = JSON.parseObject(resStr);	
	    System.out.println(resJson);
	}
}
